package com.journaldev.spring.model;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name="xaphuong")
public class Ward {
	
	public Ward() {
	}
	
	public Ward(int id, String wardName, District belongToDistrict) {
		super();
		this.id = id;
		this.wardName = wardName;
		this.belongToDistrict = belongToDistrict;
	}
	
	@Id
	@Column(name="id_xaphuong")
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int id;

	public int getId() {
		return id;
	}
	
	public void setId(int id) {
		this.id = id;
	}
	
	@Column(name="xaphuong")
	private String wardName;

	public String getWardName() {
		return wardName;
	}

	public void setWardName(String wardName) {
		this.wardName = wardName;
	}
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "id_quanhuyen")
	private District belongToDistrict;

	public District getBelongToDistrict() {
		return belongToDistrict;
	}

	public void setBelongToDistrict(District belongToDistrict) {
		this.belongToDistrict = belongToDistrict;
	}
	
	//orphanRemoval : when set to true , and delete 1 object in set ==> delete that object in db too
	@OneToMany(cascade=CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "belongToWard", orphanRemoval = true)
	private Set<Patient> patents;

	public Set<Patient> getPatents() {
		return patents;
	}

	public void setPatents(Set<Patient> patents) {
		this.patents = patents;
	}

}
